package com.glory.dmegcpda.adapter

import android.text.Editable
import android.text.TextWatcher
import com.chad.library.adapter.base.BaseQuickAdapter
import com.glory.dmegcpda.R
import com.glory.dmegcpda.base.DataBindBaseViewHolder
import com.glory.dmegcpda.bean.KeepInfoEntity
import com.glory.dmegcpda.databinding.ItemPartListBinding

import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_DateUtils

/**
 * FileName: CheckInfoAdapter
 * Author: XJH
 * Date: 2021/10/21 16:33
 * Description:
 * History:
 */
class PartAdapter(data: List<KeepInfoEntity.PmsSheetDataEntity.PartDataEntity>) :
    BaseQuickAdapter<KeepInfoEntity.PmsSheetDataEntity.PartDataEntity, DataBindBaseViewHolder>(
        R.layout.item_part_list,
        data as MutableList<KeepInfoEntity.PmsSheetDataEntity.PartDataEntity>
    ) {
    override fun convert(helper: DataBindBaseViewHolder, item: KeepInfoEntity.PmsSheetDataEntity.PartDataEntity) {
        val binging : ItemPartListBinding = helper.getDataBinding() as ItemPartListBinding
        binging.partItem = item
        binging.etNumber.setText(item.USEDQTY.toString())
        item.LASTCHANGETIME = FreeApi_DateUtils.getNowStringDate("yyyy/MM/dd HH:mm:ss")
        binging.etNumber.addTextChangedListener(object : TextWatcher{
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {

            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {

            }

            override fun afterTextChanged(s: Editable?) {
                if (s.toString().isEmpty()){
                    item.USEDQTY = 0
                }else{
                    item.USEDQTY = s.toString().toInt()
                }
            }

        })
        binging.executePendingBindings()
    }

//    private fun getDialog(commonCallback: onConfirmListener): MaterialDialog {
//        val dialog = MaterialDialog(mContext)
//            .cancelable(true)
//            .cornerRadius(12f)
//        val inflate = View.inflate(mContext, R.layout.dialog_part, null)
//        val rvPartInfoList = inflate.findViewById<RecyclerView>(R.id.rvPartInfoList)
//        val tvRight = inflate.findViewById<TextView>(R.id.tvRight)
//        val partInfoAdapter = PartInfoAdapter(partList)
//        rvPartInfoList.adapter = partInfoAdapter
//        tvRight.setOnClickListener{
//            if (partInfoAdapter.position == -1){
//                Toast.makeText(mContext,"请选择零部件",Toast.LENGTH_SHORT).show()
//                return@setOnClickListener
//            }
//            commonCallback.onConfirm(partList[partInfoAdapter.position].EQPTYPE)
//            dialog.dismiss()
//        }
//        dialog.setContentView(inflate)
//
//        return dialog
//    }
//
//    internal interface onConfirmListener {
//        fun onConfirm(s: String)
//    }
}